package edu.tyut.game.service.impl;

import edu.tyut.game.dao.poem.PoemDao;
import edu.tyut.game.model.PoemPoet;
import edu.tyut.game.service.PoemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
public class PoemServiceImpl implements PoemService {

    private PoemDao poemDao;
    @Autowired
    public void setPoemDao(PoemDao poemDao) {
        this.poemDao = poemDao;
    }

    @Override
    public boolean isExistPoem(String content) {
        List<Integer> poemIdList = poemDao.getPoemId(content);
        log.info("poemID: " + poemIdList);
        return poemIdList.size() > 0;
    }

    @Cacheable(cacheNames = "dynasties")
    @Override
    public List<String> getDynasties() {
        return poemDao.getDynasties();
    }

    @Cacheable(cacheNames = "poems", key = "#dynasty")
    @Override
    public List<PoemPoet> getPoemListByDynasty(String dynasty) {
        // log.debug("getPoemListByDynasty");
        // log.info(poemListByDynasty.toString());
        return poemDao.getPoemListByDynasty(dynasty);
    }

    @Cacheable(cacheNames = "content", key = "#content")
    @Override
    public List<PoemPoet> getPoemListBySearch(String content) {
        log.debug("getPoemListBySearch");
        return poemDao.getPoemListBySearch(content);
    }

    @Override
    public List<PoemPoet> getPoemOrderByClickCount() {
        return poemDao.getPoemOrderByClickCount();
    }
}
